package com.linkage.usercenter.controller;

import cn.hutool.core.util.StrUtil;
import com.linkage.common.base.RequestInfo;
import com.linkage.common.base.ResponseInfo;
import com.linkage.usercenter.pojo.entity.CoreUser;
import com.linkage.usercenter.pojo.entity.MeetingInfo;
import com.linkage.usercenter.service.IuserToolService;
import com.linkage.usercenter.service.MeetingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class MettingController {

    @Autowired
    private MeetingService meetingService;

    @PostMapping("/meeting/queryList")
    public String queryMeetingList(@RequestBody RequestInfo<MeetingInfo> requestInfo){
        if(StrUtil.isEmpty(requestInfo.getBase().getUsertoken())){
            return ResponseInfo.error("userToken参数为空").toString();
        }
        String dptCode = requestInfo.getBase().getUsertoken().split(":")[1];
        if(StrUtil.equals("CJGLY-3",requestInfo.getBase().getUsertoken().split(":")[2])){
            dptCode = "POLICE-0001";
        }
        List<MeetingInfo> meetingInfoList = meetingService.queryMeetingList(dptCode);
        return ResponseInfo.success(meetingInfoList).toString();
    }

    @PostMapping("/meeting/addMeeting")
    public String addMeeting(@RequestBody RequestInfo<MeetingInfo> requestInfo){
        MeetingInfo meetingInfo = requestInfo.getBuss();
        if(StrUtil.hasEmpty(meetingInfo.getMeetingName(),meetingInfo.getUserids(),meetingInfo.getFlag())){
            return ResponseInfo.error("flag，meetingName，userIds或有一参数为空").toString();
        }
        meetingService.addMeeting(meetingInfo);
        return ResponseInfo.success("新增成功").toString();
    }

    @PostMapping("/meeting/modifyMeeting")
    public String modifyMeeting(@RequestBody RequestInfo<MeetingInfo> requestInfo){
        MeetingInfo meetingInfo = requestInfo.getBuss();
        if(StrUtil.isEmpty(meetingInfo.getMeetingId())){
            return ResponseInfo.error("会议id参数为空").toString();
        }
        meetingService.updateMeeting(meetingInfo);
        return ResponseInfo.success("修改成功").toString();
    }

    @PostMapping("/meeting/deleteByDptCode")
    public String deleteMeetingByDptCode(@RequestBody RequestInfo<MeetingInfo> requestInfo){
        MeetingInfo meetingInfo = requestInfo.getBuss();
        if(StrUtil.isEmpty(meetingInfo.getDptCode())){
            return ResponseInfo.error("部门code参数为空").toString();
        }
        meetingService.deleteMeetingByDptCode(meetingInfo.getDptCode());
        return ResponseInfo.success("删除成功").toString();
    }

    @PostMapping("/meeting/deleteById")
    public String deleteById(@RequestBody RequestInfo<MeetingInfo> requestInfo){
        MeetingInfo meetingInfo = requestInfo.getBuss();
        if(StrUtil.isEmpty(meetingInfo.getMeetingId())){
            return ResponseInfo.error("meetingId参数为空").toString();
        }
        meetingService.deleteMeeting(meetingInfo.getMeetingId());
        return ResponseInfo.success("删除成功").toString();
    }
}
